package controller

import (
	"gin/response"
	"gin/service"
	"gin/types/request"
	"github.com/gin-gonic/gin"
)

// GenerateTempSecretKey 生成临时秘钥
func GenerateTempSecretKey(ctx *gin.Context) {

	var req request.GenerateTempSecretKeyReq
	_ = ctx.ShouldBindJSON(&req)
	data, err := service.GenerateTempSecretKey(req.BuckName, nil)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	response.Success(ctx, gin.H{"data": data}, "OK")
}

func GetResourceTempUrl(ctx *gin.Context) {
	var req request.GetResourceTempUrlReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	data, err := service.GetResourceTempUrl(req.BuckName, req.ResourceKey)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	response.Success(ctx, gin.H{"data": data}, "OK")
}

func GetBathResourceTempUrl(ctx *gin.Context) {
	var req request.GetBathResourceTempUrlReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	data, err := service.GetBathResourceTempUrl(req.BuckName, req.ResourceKey)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	response.Success(ctx, gin.H{"data": data}, "OK")
}
